import java.util.LinkedList;

import model.Message;

public class WorkQueue {
    private LinkedList<Message> queue;
    
    public WorkQueue(){
    	queue = new LinkedList<Message>();
    }

    public synchronized void addWork(Message m) {
    	System.out.println("New Work Added!");
        queue.addFirst(m);
        notify();
    }

    public synchronized Message getWork() {
        while (queue.isEmpty()) {
        	System.out.println("Waiting for work!");
            try {
				wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
				return null;
			}
        }
        System.out.println("Work taken!");
        return queue.removeLast();
    }
}